<?php

namespace App\Http\Controllers\Admin\Superadmin;

use Illuminate\Http\Request;
use Hash;
use DB;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class ShufflingController extends Controller
{	

    public function getIndex()
    {
    	$res = DB::table('hs_books')->get();
    	

    	return view('admin.superadmin.shuffling.index',['res'=>$res]);
    }
   
    public function getTop($id)

    {

    	//top值为1时切换为首页轮播图片
    	$data['top'] = 1;
    	$res = DB::table('hs_books')->where('id',$id)->update($data);
    	if($res){
    		return redirect('/admin/superadmin/shuffling/index')->with('success','切换成功');
    	}else{
    	 	return back()->with('error','切换失败');
    	}
    }

    public function getEdit($id)
    {
    	$data = DB::table('hs_books')->where('id',$id)->get();
    	
    	return view('admin.superadmin.shuffling.edit',['data'=>$data]);
    }


    public function postUpdate(request $request)
    {
    	// dd($request->all());
    	$data = $request->except('_token','b_pic');
    	$res = DB::table('hs_books')->insert($data);

    	if($res){
			return redirect('/admin/superadmin/shuffling/index')->with('success','用户分配成功');
		}else{
			return back()->with('error','用户分配失败');
		}		 

    }
}	
